//
//  TopNavagationBarView.m
//  Youhuiju
//
//  Created by yutenys on 16/7/20.
//  Copyright © 2016年 yutenys. All rights reserved.
//

#import "TopNavagationBarView.h"

@interface TopNavagationBarView ()

@property(nonatomic,strong)UIButton *leftBtn;//左侧按钮
@property(nonatomic,strong)UIButton *rightBtn;//右边按钮
@property(nonatomic,strong)YOSearchBar *mySearchBar;//搜索框
@property (strong, nonatomic) UIButton *searchButton;
@end

@implementation TopNavagationBarView

-(instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self)
    {
        [self creatView];
    }
    return self;
}

-(void)creatView
{
//    self.leftBtn = [UIButton buttonWithType:UIButtonTypeSystem];
    
    //右侧点击按钮
    self.rightBtn = [UIButton buttonWithType:UIButtonTypeSystem];
    self.rightBtn.tag = 1;
    _rightBtn.backgroundColor = [UIColor clearColor];
    [_rightBtn setBackgroundImage:LoadImage(@"email") forState:UIControlStateNormal];
    [self.rightBtn addTarget:self action:@selector(search:) forControlEvents:UIControlEventTouchUpInside];
    [self addSubview:_rightBtn];
    [_rightBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(self.mas_right).offset(-28 * FitW);
        make.centerY.equalTo(self.mas_centerY);
        make.size.mas_offset(CGSizeMake(24 * FitW, 24 * FitH));
        
        
    }];
    
    //左侧点击按钮
    self.leftBtn = [UIButton buttonWithType:UIButtonTypeSystem];
    self.leftBtn.tag = 2;
//    _leftBtn.backgroundColor = [UIColor redColor];
    [_leftBtn setBackgroundImage:LoadImage(@"category") forState:UIControlStateNormal];
    [self.leftBtn addTarget:self action:@selector(search:) forControlEvents:UIControlEventTouchUpInside];
    [self addSubview:_leftBtn];
    [_leftBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.mas_left).offset(28 * FitW);
        make.centerY.equalTo(self.mas_centerY);
        make.size.mas_offset(CGSizeMake(21 * FitW, 21 * FitH));
        
        
    }];
    
    //搜索栏
    self.mySearchBar = [[YOSearchBar alloc]init];
    self.mySearchBar.backgroundColor = [UIColor clearColor];
//    _mySearchBar.backgroundColor = [UIColor colorWithHexString:@"e5e5e5"];
    [self addSubview:_mySearchBar];
    [_mySearchBar mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(self.rightBtn.mas_left).offset(-15 * FitW);
        make.left.equalTo(self.leftBtn.mas_right).offset(15 * FitW);
        make.centerY.equalTo(self.mas_centerY);
        make.height.mas_offset(30 * FitH);
        
    }];
    
    //搜索框点击button
    self.searchButton = [UIButton buttonWithType:UIButtonTypeCustom];
    self.searchButton.tag = 0;
    self.searchButton.backgroundColor = [UIColor clearColor];
    [self addSubview:self.searchButton];
    
    [self.searchButton addTarget:self action:@selector(search:) forControlEvents:UIControlEventTouchUpInside];
    
    [self.searchButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.equalTo(self.mySearchBar);
    }];
    
    
//    self.bottomLineView = [[UIView alloc]init];
//    self.bottomLineView.backgroundColor = [UIColor colorWithHexString:@"eeeeee"];
//    [self addSubview:self.bottomLineView];
//    [self.bottomLineView mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.left.equalTo(self.mas_left);
//        make.right.equalTo(self.mas_right);
//        make.bottom.equalTo(self.mas_bottom);
//        make.height.mas_equalTo(1 );
//    }];




}

- (void)search:(UIButton *)sender{
    if(self.searchHandler){
        self.searchHandler(sender.tag);
    }
}
@end
